import socket

HOST = '127.0.0.1'  # 服务器IP地址，为本机地址
PORT = 8888  # 服务器端口号

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))  # 连接服务器

    while True:
        message = input("Input message (input 'q' to quit): ")
        if message == 'q':
            break
        s.sendall(message.encode('utf-8'))  # 发送数据
        data = s.recv(1024)  # 接收数据
        print(f"Received: {data.decode('utf-8')}")